Add AWS Bedrock support to ai-gateway-provider#521
Conversation
Bedrock was listed as a provider but requests failed with "provider not
supported" because no URL regex or endpoint transform existed in the
provider registry. This commit wires up full support:
- Add provider config for aws-bedrock in providers.ts with URL regex
matching bedrock-runtime.{region}.amazonaws.com and endpoint transform
that produces bedrock-runtime/{region}/{path}
- Fix amazon-bedrock.ts provider wrapper to inject CF_TEMP_TOKEN into
accessKeyId/secretAccessKey (Bedrock uses AWS SigV4, not apiKey)
- Add extraStripHeaders for AWS SigV4 companion headers (x-amz-date,
x-amz-security-token, x-amz-content-sha256), stripped only when
BYOK mode is detected via CF_TEMP_TOKEN — real credentials are
preserved when provided by the user
- Add ProviderConfig type to providers.ts for type safety
- Add endpoint transform tests including URL-encoded model IDs
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
ArshVermaGit
left a comment
There was a problem hiding this comment.
Really solid addition overall — this closes the gap for Bedrock support cleanly and the approach makes sense, especially handling AWS SigV4 separately instead of forcing it through the generic authWrapper. I also like that the header stripping is scoped only to BYOK mode, which avoids accidentally breaking user-supplied credentials. The endpoint transform coverage for URL-encoded model IDs is a nice catch too since Bedrock model naming can get tricky. Given the added tests, manual end-to-end verification, and no regressions in existing providers, this looks ready to merge from my side.
Summary
ai-gateway-providerpackagebedrock-runtime.{region}.amazonaws.comwith endpoint transform producingbedrock-runtime/{region}/{path}(matching Cloudflare AI Gateway's expected format)amazon-bedrock.tsprovider wrapper to handle Bedrock's AWS SigV4 auth model (accessKeyId/secretAccessKey) instead of the genericauthWrapperwhich only supportsapiKeyx-amz-date,x-amz-security-token,x-amz-content-sha256) only in BYOK mode (whenCF_TEMP_TOKENis detected) — user-provided credentials are preservedProviderConfigtype for type safety across the provider registryv1%3A0)Context
The Bedrock provider wrapper existed (
providers/amazon-bedrock.ts) but requests failed with"provider not supported"because:providers.tsmatched Bedrock'sbedrock-runtime.{region}.amazonaws.comURLsauthWrappertried to setapiKey, but Bedrock usesaccessKeyId/secretAccessKeyfor AWS SigV4 signingUsage
Test plan
🤖 Generated with Claude Code